import 'package:flutter_nb_net/flutter_net.dart';

class HomeDeviceInfoResp extends BaseNetModel {
  int? code;
  String? msg;
  HomeDeviceInfoData? data;

  HomeDeviceInfoResp({this.code, this.msg, this.data});

  @override
  fromJson(Map<String, dynamic> json) {
    return HomeDeviceInfoResp(
      code: json['code'],
      msg: json['msg'],
      data: json['data'] == null ? null : HomeDeviceInfoData().fromJson(json['data']),
    );
  }
}

class HomeDeviceInfoData extends BaseNetModel {
  int? deviceCount;
  DeviceInfoVO? deviceInfo;

  HomeDeviceInfoData({this.deviceCount, this.deviceInfo});

  @override
  fromJson(Map<String, dynamic> json) {
    return HomeDeviceInfoData(
      deviceCount: json['deviceCount'],
      deviceInfo: json['deviceInfo'] == null ? null : DeviceInfoVO().fromJson(json['deviceInfo']),
    );
  }
}

class DeviceInfoVO extends BaseNetModel {
  String? iccid;
  String? imei;
  String? deviceName;
  bool? activated;
  bool? vipService;
  bool? valueAddedService;
  bool? expired;
  int? deviceStatus;
  String? heartbeatTime;
  int? batteryPercentage;
  int? satellitesNums;
  int? csq;
  bool? showRechargeTip;
  bool? isNineDevice;
  int? trackStorageDays;
  DateTime? gpsInstantModeExpiryTime;

  DeviceInfoVO(
      {this.iccid,
      this.imei,
      this.deviceName,
      this.activated,
      this.vipService,
      this.valueAddedService,
      this.expired,
      this.deviceStatus,
      this.heartbeatTime,
      this.batteryPercentage,
      this.satellitesNums,
      this.csq,
      this.showRechargeTip,
      this.isNineDevice,
      this.trackStorageDays,
      this.gpsInstantModeExpiryTime});

  @override
  fromJson(Map<dynamic, dynamic> json) {
    return DeviceInfoVO(
      iccid: json['iccid'],
      imei: json['imei'],
      deviceName: json['deviceName'],
      activated: json['activated'],
      vipService: json['vipService'],
      valueAddedService: json['valueAddedService'],
      expired: json['expired'],
      deviceStatus: json['deviceStatus'],
      heartbeatTime: json['heartbeatTime'],
      batteryPercentage: json['batteryPercentage'],
      satellitesNums: json['satellitesNums'],
      csq: json['csq'],
      showRechargeTip: json['showRechargeTip'],
      isNineDevice: json['isNineDevice'],
      trackStorageDays: json['trackStorageDays'],
      gpsInstantModeExpiryTime:
          json['gpsInstantModeExpiryTime'] != null ? DateTime.parse(json['gpsInstantModeExpiryTime']) : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'iccid': iccid,
      'imei': imei,
      'deviceName': deviceName,
      'activated': activated,
      'vipService': vipService,
      'valueAddedService': valueAddedService,
      'expired': expired,
      'deviceStatus': deviceStatus,
      'heartbeatTime': heartbeatTime,
      'batteryPercentage': batteryPercentage,
      'satellitesNums': satellitesNums,
      'csq': csq,
      'showRechargeTip': showRechargeTip,
      'isNineDevice': isNineDevice,
      'trackStorageDays': trackStorageDays,
      'gpsInstantModeExpiryTime': gpsInstantModeExpiryTime?.toIso8601String(),
    };
  }

  // 判断秒定模式是否到期
  bool isInstantModeExpired() {
    return gpsInstantModeExpiryTime == null || gpsInstantModeExpiryTime!.isBefore(DateTime.now());
  }
}
